# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgname=startdde
pkgver=6.0.10
pkgrel=4
pkgdesc="starter of deepin desktop environment"
arch=('loong64' 'x86_64')
url="https://github.com/linuxdeepin/startdde"
license=('GPL3')
depends=('deepin-daemon' 'deepin-session' 'deepin-polkit-agent' 'deepin-file-manager'
         'deepin-session-shell' 'deepin-session-ui' 'libgnome-keyring' 'deepin-wloutput-daemon'
         'deepin-kwin')
makedepends=('cmake' 'coffeescript' 'go' 'git' 'jq')
groups=('deepin')
source=("https://github.com/linuxdeepin/startdde/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('903801976dd9790c15d16b16f5b12c0ab4d03fd61495913f34d34b483a1a9bec7504cf946225210b043005f232bc25f7a79457b56b8d141444a4e3268a202714')

prepare() {
  cd startdde-$pkgver
  sed -i 's/sbin/bin/' Makefile
  sed -i 's|/etc/os-version|/etc/uos-version|' misc/Xsession.d/00deepin-dde-env
}

build() {
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

  cd startdde-$pkgver
  make
}

package() {
  cd startdde-$pkgver
  make DESTDIR="$pkgdir" install

  # Fix env file permission
  chmod +x "$pkgdir"/etc/X11/Xsession.d/*

  # Don't rely on deepin-session's location
  install -dm755 "$pkgdir"/etc/X11/xinit/xinitrc.d
  mv "$pkgdir"/etc/X11/Xsession.d/* "$pkgdir"/etc/X11/xinit/xinitrc.d/
  rmdir "$pkgdir"/etc/X11/Xsession.d
}
